# main.py 示例
from utils.backtest_engine import BacktestEngine
# from strategies.唐齐安通道突破策略55日 import MyStrategy
from strategies.唐齐安通道反转策略130日 import MyStrategy
# from utils.data_loader import DataLoader
from utils.reporter import generate_report,generate_reportText
import datetime
import time
from utils.logger import Loggers

log = Loggers('马丁策略50层仓位')

config_down_instId = [
    # 'DOGE',
    # 'ETH',
# 'TON','DOGE','XRP','PEOPLE','BNB','LINK','TRX','DOT','AVAX',
'BTC',
#     'SOL',
#     'SSV',
#     'ADA',

#         # 100 - 500 亿
#     'SUI','WBTC','STETH',
#     # 50 - 100 亿
#     'PEPE','LTC','BCH','XLM','HBAR','LEO',
    # 群友推荐【恋爱绝缘体】
    # 'AAVE',
    # 群友推荐【见微知著】
    
    # 'ALCH',
]

if __name__ == '__main__':
    # dataload = DataLoader()
    # dataload.convert_csv('BTC-USDT-SWAP_15m.csv')
    # log.info("<<<<<==================空单马丁回测表现====>>>>>")

    for item in config_down_instId:
        # bicode = 'BTC'
        bicode = item
        timeType = '4h'
        # timeType = '1d'
        root_path = "D:/pythonWWW/quant_trading"
        data_path = f'{root_path}/robot_system/trading_data/{bicode}-USDT-SWAP_15m.csv'
        
        # 调参时间段
        fromdate = datetime.datetime(2025, 1, 1)
        todate = datetime.datetime(2025, 2, 1)

        # fromdate = datetime.datetime(2019, 1, 1)
        # todate = datetime.datetime(2022, 1, 1)

        # fromdate = datetime.datetime(2024, 1, 1)
        # todate = datetime.datetime(2026, 1, 1)

        engine = BacktestEngine(
            strategy_class=MyStrategy,
            data_path=data_path,
            fromdate=fromdate,
            todate=todate,
            cycle=timeType
        )
        # 策略运行
        results,cerebro = engine.run(initial_cash=1000)
        if results!=None:
            resultText = generate_reportText(results,f"{bicode} {timeType}策略")
            print(resultText)
            log.info(resultText)
        # time.sleep(1)
        # 绘制蜡烛图表
        cerebro.plot(
            style='candle', # 蜡烛图
            bardown='red',  
            barup='green',
            iplot=True, # 启用交互图表
            usebox=True, # 显示数据框（鼠标悬停显示数值）

            # plotdist=0.5,    # 调整子图间距
            # plotyval=True,   # 在 Y 轴显示数值
            plotlinelabels=True,  # 显示线条标签
            )
        

        # exit()
        # 绘制简单图表
        # cerebro.plot()
        # generate_report(results,'./html/index.html','BTC 15分钟均线策略')
        # print('图表生成成功')
